<template>
	<view class="page-appoint">
		<view class="atv">
			<view class="atvsv"><view  :class="{atc:currentTab==1}" @click="currentTabs(1)">正在预约</view></view>
			<view class="atvsv"><view :class="{atc:currentTab==2}" @click="currentTabs(2)">完成预约</view></view>
		</view>
		<view @click="qx" v-show="currentTab==1" class="qxrw">取消任务</view>
		<view class="appoint-item" :class="{'itv':cur==item.id}" v-for="item in list" :key="item.id" @click="addxz(item)">
				<view>预约时间：{{item.times}}</view>
				<view>委托单号：{{item.orderons}}</view>
				<view>保税区授权:{{item.swg==1?'授权':'未授权'}}</view>
				<view>货&#12288;&#12288;名：{{item.hname}}</view>
				<view>船&#12288;&#12288;名：{{item.shipnam}}</view>
				<view>航&#12288;&#12288;次：{{item.hc}}</view>
				<view>车&#12288;&#12288;队：{{item.cdname}}</view>
				<view>班&#12288;&#12288;次：{{item.name1}}-{{item.name2}}</view>
				<!-- <view>班&#12288;&#12288;次：{{item.datetime==1?'早班':item.datetime==2?'午班':'晚班'}}</view> -->
				<view>授权时间：{{item.sqstartime}}-{{item.sqendtime}}</view>
				<view>类&#12288;&#12288;型：{{item.rytype==1?item.clnum+' 辆':'有任务'}}</view>
				<view>完成总量：{{item.wcnum==null?0:item.wcnum}} 吨</view>
				<view v-if="item.rytype==2">绑定司机：{{item.bdsj}}</view>
				<view v-show="item.status==1">任务状态：正在进行</view>
				<view v-show="item.status==2">任务状态：完成预约</view>
				<view v-show="item.status==3">任务状态：超时取消</view>
		</view>
		<view class="appoint-item"  v-show="list.length==0">
				<view >暂无预约数据</view>
		</view>
			<tabBar :pagePath="'/pages/lshz/lhcx'"></tabBar>
	</view>
</template>
<script>
	import {
	  request
	} from '@/util/request.js'
	export default {
		data() {
			return {
				udata:'',
				list:[],
				currentTab:1,
				cur:'',
				curinfo:'',
			}
		},
		created() {
			this.init()
		},
		onShow() {
			this.init()
		},
		methods: {
			addxz(e){
				this.cur = e.id
				this.curinfo = e
			},
			currentTabs(e){
				this.currentTab = e
				this.init()
			},
			
			async bangd(e){
					uni.navigateTo({
						url:'/pages/adduser/adduser?yid='+e.id+'&cdid='+e.cdid
					})
			},
			async erweima(e){
					uni.navigateTo({
						url:'/pages/erweima/erweima?yid='+e.id+'&cdid='+e.cdid
					})
			},
			async detailyuy(e){
					uni.navigateTo({
						url:'/pages/detailyuy/detailyuy?id='+e.id
					})
			},
			async getuserinfo(){
				let data = {
					id:uni.getStorageSync('uid')
				}
				let res =  await this.$api.getuserinfo(data)
				console.log(res.data.code)
				if(res.data.code==0){
					this.udata = res.data.data
			
				}
			},
			async init() {
				let data = {
					uid:uni.getStorageSync('uid'),
					currentTab:this.currentTab,
				}
				let res = await request('/api/Linshz/getyuylist/', 'post',data)
				// let res = await this.$api.getyuylist(data)
				this.getuserinfo()
				console.log(res.data.data)
				this.list = res.data.data
			},
			
			
				qx(e){
					let that = this
					uni.showModal({
						title: '是否取消当前授权',
						content: '取消授权',
						success: function (res) {
							if (res.confirm) {
								that.delcdorderons(e)
								console.log('用户点击确定');
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					});	
				},
			
			
			async delcdorderons(e){
				if(this.cur==''){
					uni.showToast({
					  title: '没有选择数据',	
					  icon:'none',
					  duration: 2000
					});
					return false;
				}
				if(this.currentTab==1){
					if(this.curinfo.status!=1){
						uni.showToast({
						  title: '当前不能取消任务',	
						  icon:'none',
						  duration: 2000
						});
						return false;
					}
				}
				
				if(this.currentTab==2){
					if(this.curinfo.status!=1){
						uni.showToast({
						  title: '当前不能取消超时任务',	
						  icon:'none',
						  duration: 2000
						});
						return false;
					}
				}
				
				let data = {
					id:this.cur,
					cdtype:uni.getStorageSync('cdtype'),
				}
				let res = await this.$api.delcdorderons(data)
				console.log(res.data.data)
				if(res.data.code==0){
					//log
					let data1 = {
						uid:uni.getStorageSync('uid'),
						msg:'取消了当前预约委托单号'+this.curinfo.orderons,
						lv:1,
						type:2,
						cz:JSON.stringify(this.curinfo)
					}	
					await this.$api.addlogs(data1)
					
					
					uni.showToast({
					  title:  res.data.msg,	
					  icon:'none',
					  duration: 2000
					});
					this.init()
				}else{
					uni.showToast({
					  title: res.data.msg,	
					  icon:'none',
					  duration: 2000
					});
				}
			},
		
		}
	}
</script>

<style lang="scss">
	.page-appoint{
		font-size: 14px;
		box-sizing: border-box;
		background-color: #e6e6e6;
		min-height: 610px;
		margin-bottom: 100px;
		padding-bottom:100px;
	}
	.fv{
		float: left;
		border: 3upx solid #3c77b7;
		padding: 10upx;
		margin-left: 30upx;
	}
	.atvsv{
		width: 50%;
		float: left;
		// height: 100upx;
		color: #6d6d6d;
		font-size: 18px;
		background-color: #FFFFFF;
	}
	.atc{
		color: #FFFFFF;
		font-size: 15px;
		background-color: #3c77b7;
		height: 100upx;
	}
	.atv{
		width: 100%;
		height: 100upx;
		overflow: hidden;
	}

	.atvsv view{
		display: block;
		line-height: 80upx;
		text-align: center;
		height: 80upx;
		width: 100%;
	}
	
.appoint-item {
	display: block;
	width: 96%;
	background-color: #ffffff;
	margin: 0 auto;
	margin-top: 10px;
	font-size: 18px;
	padding: 20upx;
	border-radius: 5px;
	padding: 40upx;
	position: relative;
	margin-bottom: 20upx;
	>view {
		font-size: 18px;
		margin-bottom: 20upx;
	}
}
.itv{
	background-color: #3c77b7;
	color: #FFFFFF;
}
.qxrw{
	height: 40px;
	line-height: 40px;
	border-radius: 10px;
	text-align: center;
	background-color: #c80806;
	width: 96%;
	margin: 0 auto;
	font-size: 20px;
	color: #ffffff;
	font-weight: 600;
}
</style>
